package com.graduation.smartparkingplatform.ServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.graduation.smartparkingplatform.Dao.OpinionMapper;
import com.graduation.smartparkingplatform.Pojo.Opinion;
import com.graduation.smartparkingplatform.Service.OpinionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OpinionServiceImpl implements OpinionService {
  @Autowired OpinionMapper opinionMapper;

  // 获取Opinion列表（分页）
  @Override
  public PageInfo<Opinion> getOpinion(Integer page, Integer count) {
    PageHelper.startPage(page, count);

    List<Opinion> opinionList = opinionMapper.getOpinion();

    PageInfo<Opinion> pageInfo = new PageInfo<>(opinionList);

    return pageInfo;
  }

  // 根据ID搜索意见
  @Override
  public Opinion searchOpinionById(Integer opinionId) {
    return opinionMapper.searchOpinionById(opinionId);
  }

  // 筛选处理/未处理意见
  public PageInfo<Opinion> searchOpinionStatus(Integer page, Integer count, Boolean status) {
    PageHelper.startPage(page, count);

    List<Opinion> opinionList = opinionMapper.searchOpinionStatus(status);

    PageInfo<Opinion> pageInfo = new PageInfo<>(opinionList);

    return pageInfo;
  }

  // 时间正序
  @Override
  public PageInfo<Opinion> OpinionByAsc(Integer page, Integer count) {
    PageHelper.startPage(page, count);

    List<Opinion> opinionList = opinionMapper.OpinionByAsc();

    PageInfo<Opinion> pageInfo = new PageInfo<>(opinionList);

    return pageInfo;
  }

  // 时间倒序
  @Override
  public PageInfo<Opinion> OpinionByDesc(Integer page, Integer count) {
    PageHelper.startPage(page, count);

    List<Opinion> opinionList = opinionMapper.OpinionByDesc();

    PageInfo<Opinion> pageInfo = new PageInfo<>(opinionList);

    return pageInfo;
  }

  // 修改Opinion状态
  @Override
  public Boolean changeOpinionStatus(Integer opinionId, Boolean status) {
    return opinionMapper.changeOpinionStatus(opinionId, status);
  }

  // 删除意见
  @Override
  public Boolean deleteOpinion(Integer opinionId) {
    return opinionMapper.deleteOpinion(opinionId);
  }
}
